package org.bspv.pharma.dao.impl;

import java.util.List;

import org.bspv.pharma.dao.SupplyDAO;
import org.bspv.pharma.model.Place;
import org.bspv.pharma.model.Supply;
import org.hibernate.SessionFactory;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Restrictions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

/**
 * 
 * @author guillaume
 * 
 */
@Repository(value = "supplyDAO")
public class SupplyDAOImpl extends AbstractHibernateDAO<Supply, Long> implements
		SupplyDAO {

    /**
     * Constructeur par défaut.
     * @param sessionFactory
     */
	@Autowired
	public SupplyDAOImpl(SessionFactory sessionFactory) {
		setSessionFactory(sessionFactory);
	}

	/**
	 * {@inheritDoc}
	 */
    @Override
    @SuppressWarnings("unchecked")
    public List<Supply> findSupplies(List<Place> places) {
        DetachedCriteria crit = DetachedCriteria.forClass(getManagedType());
        crit.add(Restrictions.in("place", places));
        crit.add(Restrictions.isNull("destructionDate"));
        return getHibernateTemplate().findByCriteria(crit);
    }
	
}